package com.xxxx.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xxxx.mapper.MenuRoleMapper;
import com.xxxx.pojo.MenuRole;
import com.xxxx.pojo.R;
import com.xxxx.service.MenuRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chao
 * @since 2022-09-26
 */
@Service
public class MenuRoleServiceImpl extends ServiceImpl<MenuRoleMapper, MenuRole> implements MenuRoleService {


    @Autowired
    private MenuRoleMapper menuRoleMapper;
    @Override
    @Transactional
    public R updateMenuRole(Integer rid, Integer[] mids) {
        LambdaQueryWrapper<MenuRole> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MenuRole::getRid, rid);
        this.remove(wrapper);
        if (rid == null || mids==null) {
            return R.success("更新成功！");
        }

        Integer len = menuRoleMapper.saveMenuRole(rid, mids);
        if (len == mids.length) {
            return R.success("更新成功！");
        }else {
            return R.error("更新失败！");
        }

    }
}
